<?php
class Course extends Zend_Db_Table
{
	protected $_name ="course";
	protected $_primary = 'course_id';


    public function getTopCourses(){
          $select = $this->select();
          $select->limit('10');
          $select->order('course_id desc');
          return $this->fetchAll($select)->toArray();
    }

//根据传来的course_id的数组，查询出所有project
    public  function getAllCourseInArray($array){

            $where=" course_id in (".implode(',',$array).")";
            $select = $this->select();
            $select->where($where);
            $select->order('course_id desc');
            $sql = $select->__toString();

            return $this->fetchAll($select)->toArray();
    }
  // 查询所有course
    public function getAllCourses($page,$perpage,$teacher_id,$search_name,$search_status){
          $where = "1=1";
          if($teacher_id!=""){
              $where.= " and teacher_id=$teacher_id";
          }else if($search_name!=""){
              $where.=" and name like '$search_name'";
          }else if($search_status!=""){
              $where.=" and status='$search_status'";
          }
          $select = $this->select();
          $select->where($where);
          if($page!=""){
          $select->limitPage($page,$perpage);
          }
          $select->order('course_id desc');
          return $this->fetchAll($select)->toArray();
    }
    
  // 查询所有course
    public function getAllCoursesexcel(){
          $where = "1=1";
          $select = $this->select();
          $select->where($where);
          $select->order('course_id asc');
          return $this->fetchAll($select)->toArray();
    }    

 //根据course_id 查询course
    public function getcourseBycourse_id($course_id){
          $select = $this->select();
          $select->where("course_id=".$course_id);
          return $this->fetchAll($select)->toArray();
    }

 //根据teacher_id 查询course
    public function getcourseByteacher_id($teacher_id){
          $select = $this->select();
          $select->where("teacher_id=".$teacher_id);
          return $this->fetchAll($select)->toArray();
    }

 //更新course
    public function updatecourseBycourse_id($array,$course_id){

		$db = $this->getAdapter();
		$where=$db->quoteInto('course_id = ?', $course_id);
		$this->update($array, $where);
	}
//删除course
     public function delcourseBycourse_id($course_id){
          $where = 'course_id = '. $course_id;
         $this->delete($where);
         return true;
    }

}

